package com.yunfeisoft.business.service.impl;

import com.yunfeisoft.business.dao.inter.OutHospitalDao;
import com.yunfeisoft.business.model.Elder;
import com.yunfeisoft.business.model.OutHospital;
import com.yunfeisoft.business.service.inter.ElderService;
import com.yunfeisoft.business.service.inter.OutHospitalService;
import com.yunfeisoft.common.base.BaseServiceImpl;
import com.yunfeisoft.common.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;

/**
 * ClassName: OutHospitalServiceImpl
 * Description: 老人出院流转表service实现
 * Author: Jackie liu
 * Date: 2020-01-13
 */
@Service("outHospitalService")
public class OutHospitalServiceImpl extends BaseServiceImpl<OutHospital, String, OutHospitalDao> implements OutHospitalService {

    @Autowired
    private ElderService elderService;

    @Override
    public Page<OutHospital> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public Page<OutHospital> myApprovalList(Map<String, Object> params) {
        return getDao().myApprovalList(params);
    }

    @Transactional
    @Override
    public void hospitalArchive(String[] idArr) {
        Arrays.asList(idArr).stream().forEach(id -> {
            // 根据出院id查询出院记录
            OutHospital outHospital = getDao().load(id);
            // 设置出院状态为院办存档
            outHospital.setStatus(OutHospital.OutHospitalStatusEnum.HOSPITAL_OFFICE_ARCHIVE.getValue());
            // 更新出院记录
            getDao().update(outHospital);
            Elder elder = new Elder();
            elder.setId(outHospital.getElderId());
            // 设置入院状态为院办存档
            elder.setStatus(Elder.ElderStatusEnum.HOSPITAL_OFFICE_ARCHIVE.getValue());
            elderService.modify(elder);
        });
    }
}